package com.ygxsk.carhome.ui.adapter;

import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.response.CardGroupHeadOrTeamCheck;
import com.ygxsk.carhome.utils.CommUtils;

import java.util.List;

/**
 * Autuhor:Administrator
 * Time:2023-03-10  21:20
 * Description: this is 小组长的列表布局内容--单选的 小组长的
 */
public class CardGroupHeadManMemberAdapter extends BaseQuickAdapter<CardGroupHeadOrTeamCheck, BaseViewHolder> {

    public CardGroupHeadManMemberAdapter(int layoutResId, @Nullable List<CardGroupHeadOrTeamCheck> data) {
        super(layoutResId, data);

        //addChildClickViewIds(R.id.constraintlayoutitemview);

    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, CardGroupHeadOrTeamCheck cardGroupHeadOrTeamCheck) {

        if (cardGroupHeadOrTeamCheck != null) {

            String headManName = cardGroupHeadOrTeamCheck.getGroupUserName();
            String headManStationName = cardGroupHeadOrTeamCheck.getBusinessDeptName();
            //是否被勾中
            int isChecked = cardGroupHeadOrTeamCheck.getIsChecked();

            //findview
            TextView textViewNameInHeadMan = (TextView) baseViewHolder.findView(R.id.textviewnameinheadman);
            TextView textViewPersonInStaionName = (TextView) baseViewHolder.findView(R.id.textviewpersoninstaionname);
            //被选中的图片内容
            CheckBox checkBoxInHeadMan = (CheckBox) baseViewHolder.findView(R.id.checkboxinheadman);
            //底部的一条横向，最后一条数据的时候 是隐藏的
            TextView textViewLineInHeadMan = (TextView) baseViewHolder.findView(R.id.textviewlineinheadman);

            CommUtils.setText(textViewNameInHeadMan, headManName);
            CommUtils.setText(textViewPersonInStaionName, headManStationName);

            //最后一条数据隐藏
            if (getItemPosition(cardGroupHeadOrTeamCheck) == getData().size() - 1) {
                textViewLineInHeadMan.setVisibility(View.GONE);
            } else {
                textViewLineInHeadMan.setVisibility(View.VISIBLE);
            }

            if (isChecked == 1) {//表示选中
                checkBoxInHeadMan.setChecked(true);
            } else if (isChecked == 0) {
                checkBoxInHeadMan.setChecked(false);
            }

        }
    }
}
